n = int(input())
a = list(map(int, input().split()))
ans = 0
if len(set(a)) != 1 and max(a) == a[-1]:
    ans = 1
else:
    if len(set(a)) == 1:
        ans = 0
    else:
        ans = 2

print(ans)